## Copyright 2007 Roee Shlomo, All Rights Reserved
# see LICENSE.txt for license information

"""
Possible RPC Errors / Error Messages
"""

class KrpcBaseError(Exception):
    def __init__(self, code = 0, msg = "KrpcBaseError", args = []):
        self.code = code
        self.msg = msg
        self.args = args
    def __str__(self):
        if self.args:
            return str(self.msg) + ": " + str(self.args[0])
        else:
            return str(self.msg)
    def __int__(self):
        return int(self.code)
    def get(self):
        return (int(self), str(self))
    
class KrpcGenericError(KrpcBaseError):
    def __init__(self, *args):
        KrpcBaseError.__init__(self, 201, 'Generic Error', args)
        
class KrpcServerError(KrpcBaseError):
    def __init__(self, *args):
        KrpcBaseError.__init__(self, 202, 'Server Error', args)
        
class KrpcProtocolError(KrpcBaseError):
    def __init__(self, *args):
        KrpcBaseError.__init__(self, 203, 'Protocol Error', args)
        
class KrpcMethodUnknownError(KrpcBaseError):
    def __init__(self, *args):
        KrpcBaseError.__init__(self, 204, 'Method Unknown', args)
